package com.zkkj.demo.utils;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * author : cyc
 * Date : 2019/11/25
 */
public class TokenUtils {

    /**
     * 通过上下文获取request
     * @return
     */
    public static HttpServletRequest getHttpServletRequest() {
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        return attributes.getRequest();
    }


    /**
     * 从request的请求头中获取token字符串
     * @return
     */
    public static String getToken(){
        return getHttpServletRequest().getHeader("Authorization");
    }
}
